"""
字符串的使用
"""

# Python 字符串三种的定义方式
string_01 = 'Blue'      # 单引号定义
string_02 = "Blue"      # 双引号定义
string_03 = """Blue"""  # 三引号定义

# 不同字符串的定义方式获取到字符串类型是相同的
print(type(string_01), string_01)
print(type(string_02), string_02)
print(type(string_03), string_03)
print()

# Python 引号的输出方式
print("\'Blue\'", "\"Blue\"")
print()

# Python 字符串的拼接
name = 'Blue'
print("I am " + name + ".", "How are you.")
# TypeError: can only concatenate str (not "int") to str
# 字符串无法直接和整数或浮点数进行拼接
# print(name + 12)
print()

# 字符串格式化
# 通过占位符, 实现字符串的拼接
name = 'Blue'
girl_friend = 'Yu'
print("I am %s. My girl friend is %s" % (name, girl_friend))
print("I am %d years old. My girl friend is %d years old" % (23, 20))
print()

# 字符串格式化的精度控制
value1 = 30
value2 = 3.1415926
print("value1 没有宽度限制, 结果为: %s" % value1)
print("value1 宽度限制5, 结果为: %5d" % value1)
print("value1 宽度限制1, 结果为: %1d" % value1)
print("value2 宽度限制3, 小数精度为 2, 结果为: %3.2f" % value2)
print("value2 没有宽度限制, 小数精度为 5, 结果为: %.5f" % value2)
print()

# 字符串格式化(快速写法)
name = 'Blue'
value1 = 30
value2 = 3.1415926
print(f"name = {name}, value1 = {value1}, value2 = {value2}")
print()

